package com.relytosoft.mizar.media.camera.services.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.camera.services.service.CameraChannelOsdService;
import com.relytosoft.mizar.media.external.api.camera.response.OSDDto;
import com.relytosoft.mizar.media.external.api.camera.response.PreviewFrameDto;
import com.relytosoft.mizar.media.external.api.camera.response.ShowStringParams;
import com.relytosoft.mizar.media.external.api.camera.response.VideoStringDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lj
 * @date 2022/4/12 14:11
 */
@Api(tags = {"通道参数"})
@RestController
@RequestMapping("/cameara/channel/osd")
public class CameraChannelOsdController {

    @Resource
    private CameraChannelOsdService cameraChannelOsdService;

    @SaCheckPermission("cameara:osd:getosd")
    @OpLog(msg = "获取视频OSD显示参数", opType = OpTypeEnum.SELECT)
    @ApiOperation("获取视频OSD显示参数")
    @GetMapping("/{cameraIndexCode}")
    public ResponseResult<OSDDto> osd(@PathVariable String cameraIndexCode) {
        OSDDto osddto = cameraChannelOsdService.getOsdInfo(cameraIndexCode);
        return ResponseResult.ok(osddto);
    }

    @SaCheckPermission("cameara:osd:showVideoString")
    @OpLog(msg = "获取视频叠加字符串参数", opType = OpTypeEnum.SELECT)
    @ApiOperation("获取视频叠加字符串参数")
    @GetMapping("showString/{cameraIndexCode}")
    public ResponseResult<VideoStringDto> showVideoString(@PathVariable String cameraIndexCode) {
        VideoStringDto videoStringDTO = cameraChannelOsdService.showVideoString(cameraIndexCode);
        return ResponseResult.ok(videoStringDTO);
    }


    @SaCheckPermission("cameara:osd:preview")
    @OpLog(msg = "获取预览画面参数配置", opType = OpTypeEnum.SELECT)
    @ApiOperation("获取预览画面参数配置")
    @GetMapping("/preview/{cameraIndexCode}")
    public ResponseResult<PreviewFrameDto> preview(@PathVariable String cameraIndexCode) {
        PreviewFrameDto previewFrameDTO = cameraChannelOsdService.previewFrame(cameraIndexCode);
        return ResponseResult.ok(previewFrameDTO);
    }

    @SaCheckPermission("cameara:osd:setosd")
    @OpLog(msg = "设置视频OSD显示参数", opType = OpTypeEnum.OTHER)
    @ApiOperation("设置视频OSD显示参数")
    @PostMapping("/set/osd")
    public ResponseResult<Void> setOsd(@RequestBody OSDDto osdDto) {
        boolean b = cameraChannelOsdService.setOsd(osdDto);
        return b ? ResponseResult.ok("设置成功") : ResponseResult.fail("设置失败");
    }

    @SaCheckPermission("cameara:osd:setOverlayString")
    @OpLog(msg = "设置视频叠加字符串参数", opType = OpTypeEnum.OTHER)
    @ApiOperation("设置视频叠加字符串参数")
    @PostMapping("/set/string/{cameraIndexCode}")
    public ResponseResult<Void> setOverlayString(@PathVariable String cameraIndexCode, @RequestBody List<ShowStringParams> showStringParamsList) {
        boolean b = cameraChannelOsdService.setOverlayString(cameraIndexCode, showStringParamsList);
        return b ? ResponseResult.ok("设置成功") : ResponseResult.fail("设置失败");
    }

    @SaCheckPermission("cameara:osd:setPreview")
    @OpLog(msg = "设置预览画面参数配置", opType = OpTypeEnum.OTHER)
    @ApiOperation("设置预览画面参数配置")
    @PostMapping("/set/preview")
    public ResponseResult<Void> setPreview(@RequestBody PreviewFrameDto previewFrameDto) {
        boolean b = cameraChannelOsdService.setPreview(previewFrameDto);
        return b ? ResponseResult.ok("设置成功") : ResponseResult.fail("设置失败");
    }

}
